<!DOCTYPE html>
<html>
<head>
    <title>账号登录</title>
    <meta content="no-cache" http-equiv="Pragma"/>
    <meta content="no-cache" http-equiv="Cache-Control"/>
    <meta content="0" http-equiv="Expires"/>
    <meta content="text/html;charset=UTF-8" http-equiv="CONTENT-TYPE"/>
    <link href="../static/style/reset.css" rel="stylesheet" type="text/css"/>
    <link href="../static/style/login.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="wrap" style="">
    <div class="login-wrap">
        <label>账号登陆</label>
        <ul>
            <li><input id="username" name="username" placeholder="用户名" type="text"/></li>
            <li>
                <div id="error_box1"></div>
            </li>
            <li><input id="password" name="password" placeholder="密码" type="password"/></li>
            <li>
                <div id="error_box2"></div>
            </li>
            <li>
                <button class="login" id="login">登录</button>
            </li>
        </ul>
    </div>
</div>

<script src="../static/js/jquery-2.2.4.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#login").click(function () {
            // 处理表单验证和交给后台处理的逻辑
            var oError1 = document.getElementById("error_box1");
            var oError2 = document.getElementById("error_box2");
            var username = $("#username").val();
            var password = $("#password").val();
            var isNotError = true;

            alert(username + password);

            if (username == "") {
                oError1.innerHTML = "用户名为空 ";
                isNotError = false;
                return;
            }
            if (password == "") {
                oError2.innerHTML = "密码为空 ";
                isNotError = false;
                return;
            }
            $.ajax({
                type: "POST",
                url: "/login/dologin",
                dataType: "json",
                data: {"username": username, "password": password},
                success: function (data) {
                    if (data.status == 0) {
                        alert("登陆成功")
                        window.location.href = "/";
                        /* Window.location.href="/SSH/car/main"; */
                    } else if (data.status == 1) {
                        alert("密码错误");
                    }
                }
            });
        });
    });
</script>
</body>

</html>
